﻿using System;
using System.Collections.Generic;
using System.Drawing.Drawing2D;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.DB;
using YJKRevitStairs.StairsModel.CommonUnit;
using YJKRevitStairs.StairsModel.DataInfos;

namespace YJKRevitStairs.StairsModel.Kit
{
	internal class SteelStairsKit : ProjectionDrawingKit
	{
		public SteelStairsKit(Autodesk.Revit.ApplicationServices.Application app) : base(app)
		{
		}

		public bool SteelStairsProfileCurves(ref SteelStairs param_stairs, bool bLRMirror, bool bTBMirror, bool bBottom, bool bTop)
		{
			bool result = true;
			LineRunData runData = param_stairs.m_RunData;
			double dStairsWidth = param_stairs.m_dStairsWidth;
			double dStairsLength = param_stairs.m_dStairsLength;
			double dRotateAngle = param_stairs.m_dRotateAngle;
			int nInsertPointIndex = param_stairs.m_nInsertPointIndex;
			List<XYZ> list = new List<XYZ>();
			XYZ zero = XYZ.Zero;
			XYZ xyz = new XYZ(runData.RunWidth, 0.0, 0.0);
			XYZ xyz2 = new XYZ(0.0, runData.RunLength, 0.0);
			XYZ xyz3 = new XYZ(runData.RunWidth, runData.RunLength, 0.0);
			param_stairs.m_RunData.PtRunBottomLeft = zero;
			param_stairs.m_RunData.PtRunBottomRight = xyz;
			param_stairs.m_RunData.PtRunTopLeft = xyz2;
			param_stairs.m_RunData.PtRunTopRight = xyz3;
			if (param_stairs.m_bRightAngle)
			{
				XYZ xyz4 = new XYZ(0.0, Common.MMToFeet(210.0), 0.0);
				XYZ item = zero - xyz4;
				XYZ item2 = xyz - xyz4;
				list.Add(item);
				list.Add(item2);
			}
			else
			{
				list.Add(zero);
				list.Add(xyz2);
				list.Add(xyz3);
				list.Add(xyz);
			}
			XYZ xyz5 = list[nInsertPointIndex];
			base.CalulateTransform(bLRMirror, bTBMirror, dRotateAngle, dStairsWidth, dStairsLength, xyz5);
			param_stairs.m_TransVector = Geometry.TransformPoint(xyz5, this.m_Transform);
			param_stairs.m_listOtherCurve.AddRange(base.DrawBasePoint(xyz5, 100.0));
			param_stairs.m_Transform = this.m_Transform;
			this.DrawSteelStairsRunCurves(ref param_stairs);
			this.DrawSteelStairsNoteInfo(ref param_stairs);
			if (!param_stairs.m_bRightAngle && param_stairs.m_bNoteUpStairs)
			{
				this.DrawUpStairsNoteInfo(ref param_stairs);
			}
			return result;
		}

		private void DrawSteelStairsRunCurves(ref SteelStairs param_stairs)
		{
			if (param_stairs != null)
			{
				if (param_stairs.m_bRightAngle)
				{
					LineRunData runData = param_stairs.m_RunData;
					double dStairsWidth = param_stairs.m_dStairsWidth;
					SingleRunCurveInfo singleRunCurveInfo = new SingleRunCurveInfo();
					singleRunCurveInfo.BottomElevation = runData.BottomElevation;
					XYZ ptRunTopLeft = runData.PtRunTopLeft;
					XYZ ptRunTopRight = runData.PtRunTopRight;
					XYZ xyz = new XYZ(0.0, Common.MMToFeet(80.0), 0.0);
					XYZ xyz2 = ptRunTopRight - xyz;
					XYZ xyz3 = ptRunTopLeft - xyz;
					singleRunCurveInfo.RunBoundaryCurvesInfoList.Add(base.NewLine(PenColor.PC_Black, DashStyle.Solid, 2f, xyz3, ptRunTopLeft, null));
					singleRunCurveInfo.RunBoundaryCurvesInfoList.Add(base.NewLine(PenColor.PC_Black, DashStyle.Solid, 2f, ptRunTopLeft, ptRunTopRight, null));
					singleRunCurveInfo.RunBoundaryCurvesInfoList.Add(base.NewLine(PenColor.PC_Black, DashStyle.Solid, 2f, ptRunTopRight, xyz2, null));
					singleRunCurveInfo.RunBoundaryCurvesInfoList.Add(base.NewLine(PenColor.PC_Black, DashStyle.Solid, 2f, xyz2, xyz3, null));
					XYZ xyz4 = new XYZ(0.0, Common.MMToFeet(130.0), 0.0);
					XYZ xyz5 = new XYZ(Common.MMToFeet(80.0), 0.0, 0.0);
					XYZ xyz6 = xyz3 - xyz4;
					XYZ xyz7 = xyz3 + xyz5;
					XYZ xyz8 = xyz7 - xyz4;
					singleRunCurveInfo.RunBoundaryCurvesInfoList.Add(base.NewLine(PenColor.PC_Black, DashStyle.Solid, 2f, xyz3, xyz6, null));
					singleRunCurveInfo.RunBoundaryCurvesInfoList.Add(base.NewLine(PenColor.PC_Black, DashStyle.Solid, 2f, xyz6, xyz8, null));
					singleRunCurveInfo.RunBoundaryCurvesInfoList.Add(base.NewLine(PenColor.PC_Black, DashStyle.Solid, 2f, xyz8, xyz7, null));
					XYZ xyz9 = xyz2 - xyz4;
					XYZ xyz10 = xyz9 - xyz5;
					XYZ ptE = xyz2 - xyz5;
					singleRunCurveInfo.RunBoundaryCurvesInfoList.Add(base.NewLine(PenColor.PC_Black, DashStyle.Solid, 2f, xyz2, xyz9, null));
					singleRunCurveInfo.RunBoundaryCurvesInfoList.Add(base.NewLine(PenColor.PC_Black, DashStyle.Solid, 2f, xyz9, xyz10, null));
					singleRunCurveInfo.RunBoundaryCurvesInfoList.Add(base.NewLine(PenColor.PC_Black, DashStyle.Solid, 2f, xyz10, ptE, null));
					param_stairs.m_listRunCurve.Add(singleRunCurveInfo);
					return;
				}
				LineRunData runData2 = param_stairs.m_RunData;
				SingleRunCurveInfo singleRunCurveInfo2 = new SingleRunCurveInfo();
				singleRunCurveInfo2.BottomElevation = runData2.BottomElevation;
				base.DrawLinearRun(runData2, runData2.PtRunBottomLeft, runData2.PtRunBottomRight, runData2.PtRunTopRight, runData2.PtRunTopLeft, ref singleRunCurveInfo2, ref param_stairs.m_listOtherCurve, param_stairs.m_bNoteUpStairs);
				param_stairs.m_listRunCurve.Add(singleRunCurveInfo2);
			}
		}

		private void DrawSteelStairsNoteInfo(ref SteelStairs param_stairs)
		{
			LineRunData runData = param_stairs.m_RunData;
			XYZ basisY = XYZ.BasisY;
			XYZ basisX = XYZ.BasisX;
			XYZ xyz = XYZ.Zero;
			XYZ ptEnd = XYZ.Zero;
			xyz = runData.PtRunTopLeft + basisY;
			ptEnd = runData.PtRunTopRight + basisY;
			base.DrawStairsNoteInfo(ref param_stairs.m_listOtherCurve, ref param_stairs.m_listText, xyz, ptEnd, "梯段宽度", 0.8, 5.0, 2.0, XYZ.BasisY, PenColor.PC_Black);
			if (!param_stairs.m_bRightAngle)
			{
				xyz = runData.PtRunTopLeft - basisX;
				ptEnd = runData.PtRunBottomLeft - basisX;
				base.DrawStairsNoteInfo(ref param_stairs.m_listOtherCurve, ref param_stairs.m_listText, xyz, ptEnd, "梯段长度", 0.8, 2.0, 5.0, -XYZ.BasisX, PenColor.PC_Black);
				XYZ xyz2 = new XYZ(0.0, runData.TreadDepth, 0.0);
				xyz = runData.PtRunBottomRight + basisX;
				ptEnd = xyz + xyz2;
				base.DrawStairsNoteInfo(ref param_stairs.m_listOtherCurve, ref param_stairs.m_listText, xyz, ptEnd, "踏步宽度", 0.8, 2.0, 5.0, XYZ.BasisX, PenColor.PC_Black);
			}
		}

		private void DrawUpStairsNoteInfo(ref SteelStairs param_stairs)
		{
			LineRunData runData = param_stairs.m_RunData;
			List<UpDownText> list = new List<UpDownText>();
			string sText = "上";
			XYZ xyz = XYZ.BasisY * 1.0;
			UpDownText item = new UpDownText(Geometry.CalculatMidPoint(runData.PtRunBottomLeft, runData.PtRunBottomRight) - xyz, sText);
			list.Add(item);
			base.DrawUpDownNoteInfo(ref param_stairs.m_listText, list);
		}
	}
}
